package com.huidu.bitrade.server;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.sql.*;

@Component
public class MysqlClient {
    @Value("${spring.datasource.driver-class-name}")
    private String driver;
    @Value("${spring.datasource.url}")
    private String url;
    @Value("${spring.datasource.username}")
    private String username;
    @Value("${spring.datasource.password}")
    private String password;
    public void client() throws SQLException, ClassNotFoundException {
        //加载驱动
        Class.forName(driver);
        //连接数据库
        Connection conn = DriverManager.getConnection(url,username,password);
        //创建命令执行对象
        Statement stmt = conn.createStatement();
        //执行对象执行SQL语句
        stmt.execute("select count(*) from system_config limit 1");
        //关闭资源
        if (stmt != null) {
            stmt.close();
            stmt=null;
        }
        if (conn != null) {
            conn.close();
            conn=null;
        }
        System.out.println("关闭资源成功");
    }

}
